package com.wuh.controller;

import com.wuh.model.TeacherComment;
import com.wuh.service.TeacherCommentService;
import com.wuh.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 教师评价表现层
 */
@Controller
public class TeacherCommentController {

    @Autowired
    private TeacherCommentService teacherCommentService;


    /**
     * 根据comentId查询评论信息
     * @param comentId
     * @param model
     * @return
     */
    public String queryCommentById(Integer comentId, Model model){
        TeacherComment teacherComment = teacherCommentService.queryCommentById(comentId);
        model.addAttribute("teacherComment",teacherComment);
        return "";
    }

    /**
     * 根据实体类动态查询评价信息
     *
     * @param teacherComment
     * @param session
     * @return
     */
    @RequestMapping("/queryTeacherCommentAll")
    public void queryTeacherCommentAll(TeacherComment teacherComment, HttpSession session) {
        List<TeacherComment> teacherComments = teacherCommentService.queryCommentAll(teacherComment);
        session.setAttribute("teacherComments", teacherComments);
    }

    /**
     * 添加教师评价信息
     * @param teacherComment
     * @return
     */
    @RequestMapping("/addComment")
    public String addComment(TeacherComment teacherComment) {
        teacherCommentService.addComment(teacherComment);
        return "redirect:/openclass/class_details";
    }

    /**
     * 修改教师评价信息
     * @param teacherComment
     * @return
     */
    @RequestMapping("/updateComment")
    public String updateComment(TeacherComment teacherComment) {
        teacherCommentService.updateComment(teacherComment);
        return "";
    }

    /**
     * 删除教师评价信息
     * @param comentId
     * @return
     */
    @RequestMapping("/deleteCommentById")
    public String deleteCommentById(Integer comentId) {
        teacherCommentService.deleteCommentById(comentId);
        return "redirect:/toUserIndex";
    }

}
